import request from '../request.ts'

// RBAC 学生管理API

// 获取用户列表（学生）
export const getStudents = (params) => {
  return request({
    url: '/rbac/users',
    method: 'get',
    params
  })
}

// 创建用户（学生）
export const createStudent = (data) => {
  return request({
    url: '/rbac/users',
    method: 'post',
    data
  })
}

// 更新用户信息（学生）
export const updateStudent = (userId, data) => {
  return request({
    url: `/rbac/users/${userId}`,
    method: 'put',
    data
  })
}

// 删除用户（学生）
export const deleteStudent = (userId) => {
  return request({
    url: `/rbac/users/${userId}`,
    method: 'delete'
  })
}

// 获取用户详情（学生）
export const getStudentById = (userId) => {
  return request({
    url: `/rbac/users/${userId}`,
    method: 'get'
  })
}

// 获取用户角色（学生）
export const getStudentRoles = (userId) => {
  return request({
    url: `/rbac/users/${userId}/roles`,
    method: 'get'
  })
}

// 分配角色给用户（学生）
export const assignRoleToStudent = (userId, roleId) => {
  return request({
    url: `/rbac/users/${userId}/roles/${roleId}`,
    method: 'post'
  })
}

// 移除用户角色（学生）
export const removeRoleFromStudent = (userId, roleId) => {
  return request({
    url: `/rbac/users/${userId}/roles/${roleId}`,
    method: 'delete'
  })
}

// 获取学生权限
export const getStudentPermissions = (userId) => {
  return request({
    url: `/rbac/users/${userId}/permissions`,
    method: 'get'
  })
}

// 批量删除学生
export const batchDeleteStudents = (userIds) => {
  return request({
    url: '/rbac/users/batch',
    method: 'delete',
    data: { userIds }
  })
}

// 重置学生密码
export const resetStudentPassword = (userId) => {
  return request({
    url: `/rbac/users/${userId}/reset-password`,
    method: 'post'
  })
}

// 切换学生状态
export const toggleStudentStatus = (userId) => {
  return request({
    url: `/rbac/users/${userId}/toggle-status`,
    method: 'post'
  })
}

// 导入学生
export const importStudents = (file) => {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: '/rbac/users/import',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 导出学生
export const updateStudentPermissions = (userId, permissions) => {
  return request({
    url: `/rbac/users/${userId}/permissions`,
    method: 'put',
    data: { permissions }
  })
}

export const exportStudents = (params) => {
  return request({
    url: '/rbac/users/export',
    method: 'get',
    params,
    responseType: 'blob'
  })
}